package org.jeecg.modules.cows.wx.controller;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.Md5Util;
import org.jeecg.common.util.PasswordUtil;
import org.jeecg.modules.cows.wx.dto.WechatLoginDTO;
import org.jeecg.modules.cows.wx.dto.WechatTokenDTO;
import org.jeecg.modules.cows.wx.param.LoginRequestParam;
import org.jeecg.modules.cows.wx.service.WechatInfoService;
import org.jeecg.modules.message.entity.SysMessage;
import org.jeecg.modules.message.service.ISysMessageService;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.model.SysLoginModel;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * @Description: 消息
 * @author: jeecg-boot
 * @date: 2019-04-09
 * @version: V1.0
 */
@Slf4j
@Api(tags="小程序通用接口")
@RestController
@RequestMapping("/wechat/service")
public class WechatServiceController extends JeecgController<SysMessage, ISysMessageService> {
	@Autowired
	private WechatInfoService wechatInfoService;

	/**
	 * 获取token
	 *
	 * @param request
	 * @param response
	 * @return
	 */
	@ApiOperation(value = "获取token", notes = "获取token")
		@PostMapping(value = "/getToken")
	public Result<WechatTokenDTO> importExcel(HttpServletRequest request, HttpServletResponse response) {
		WechatTokenDTO wechatTokenDTO = wechatInfoService.getToken();
		return Result.ok(wechatTokenDTO);
	}

	@ApiOperation("登录接口")
	@RequestMapping(value = "/login", method = RequestMethod.POST)
	public Result<WechatLoginDTO> login(@RequestBody LoginRequestParam param){
		WechatLoginDTO wechatLoginDTO = wechatInfoService.wxLogin(param.getJsCode());
		return Result.ok(wechatLoginDTO);
	}

}
